#import "SDCaseManageCell.h"
#import "SDCaseManageModel.h"



@interface SDCaseManageCell ()

//分割
@property (nonatomic,strong)UIImageView * im_carveView;
@property (nonatomic,strong)UIView * carveView;
//显示时间label
@property (nonatomic,strong)UILabel * lb_time;
//病情图片
@property (nonatomic,strong)UIImageView * im_image;
//疾病类型
@property (nonatomic,strong)UILabel * lb_disease;
//基本类型
@property (nonatomic,strong)UILabel * lb_basic;
//病情描述
@property (nonatomic,strong)UILabel * lb_describe;
@end

@implementation SDCaseManageCell
#pragma mark - 初始化方法
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self showCellSubView];
    }
    return self;
}
#pragma mark - 初始化控件方法
- (void)showCellSubView{
    //MARK: - 分割线和圈圈
    self.im_carveView = [self newImageAndImageName:@"illness_rb_img_sel.png"];
    UIView * vie = [[UIView alloc]init];
    vie.backgroundColor = [UIColor colorWithRed:0.4314 green:0.8392 blue:0.8275 alpha:1.0];
    [self addSubview:vie];
    self.carveView = vie;
    
    
    self.lb_time = [self newLabel];
    
     self.im_image = [self newImageAndImageName:@"h1"];
    
    self.lb_disease = [self newLabel];
    
    
    self.lb_basic = [self newLabel];
    
    self.lb_describe = [self newLabel];
    
    [self setUi];
    
}

#pragma mark - 子控件约束方法
- (void)setUi{
    
    [self.im_carveView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.leading.offset(0);
        make.width.height.offset(30);
    }];
    
    [self.carveView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.im_carveView.mas_bottom);
        make.centerX.mas_equalTo(self.im_carveView.mas_centerX);
        make.bottom.offset(0);
        make.width.offset(2);
    }];
    
    [self.lb_time mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.im_carveView.mas_trailing).offset(5);
        make.centerY.mas_equalTo(self.im_carveView.mas_centerY);
        make.height.mas_equalTo(30);
    }];
    
    [self.im_image mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.leading.mas_equalTo(self.lb_time.mas_leading);
        make.top.mas_equalTo(self.lb_time.mas_bottom).offset(10);
        make.width.mas_equalTo(100);
        make.height.offset(100);
    }];
   
    [self.lb_disease mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.im_image.mas_top).offset(10);
        make.left.mas_equalTo(self.im_image.mas_right).offset(10);
    }];
    
    [self.lb_basic mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.lb_disease.mas_bottom).offset(20);
        make.left.mas_equalTo(self.im_image.mas_right).offset(10);
    }];
    
    [self.lb_describe mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.im_image.mas_right).offset(10);
        make.right.mas_equalTo(-10);
        make.top.mas_equalTo(self.lb_basic.mas_bottom).offset(15);
        make.height.mas_greaterThanOrEqualTo(30);
        make.bottom.mas_equalTo(self.mas_bottom).offset(-20);
        
    }];
    
    
}

#pragma mark - 重写选择cell方法
- (void)setSelected:(BOOL)selected animated:(BOOL)animated{
    
}

#pragma mark - 重写model属性set方法
- (void)setCaseManageModel:(SDCaseManageModel *)caseManageModel{
    
    _caseManageModel =caseManageModel;
    //MARK: - 根据model给子控件赋值
//    self.im_image.image = caseManageModel.imageIC;

    self.im_image.image = caseManageModel.array.lastObject;
    self.lb_disease.text = [NSString stringWithFormat:@"疾病类型:  %@",caseManageModel.disease];
    self.lb_basic.text = [NSString stringWithFormat:@"基本类型:  %@",caseManageModel.basic];
    self.lb_describe.text = caseManageModel.describe;
    self.lb_time.text = caseManageModel.timeString;
    
    //MARK: - 根据是否有图片重设约束
    if (caseManageModel.array.lastObject == nil) {
        
        [self.im_image mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.width.offset(0.01);
        }];
        
            if (caseManageModel.describe == nil) {
            [self.lb_describe mas_updateConstraints:^(MASConstraintMaker *make) {
               make.height.mas_greaterThanOrEqualTo(10);
            }];
        
            }else{
        
                [self.lb_describe mas_updateConstraints:^(MASConstraintMaker *make) {
                   make.height.mas_greaterThanOrEqualTo(30);
                }];
        
            }
        
    }else{
        [self.im_image mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.width.offset(100);
        }];
    }
    
}

- (UIImageView *)im_image
{
    
    if (_im_image == nil) {
        
        _im_image = [self newImageAndImageName:@"h1"];
    }
    return _im_image;
}

#pragma mark - label创建的封装方法
- (UILabel *)newLabel{
    
    UILabel * tempLabel = [[UILabel alloc]init];
    
    tempLabel.numberOfLines = 0;
    
    [tempLabel setFont:[UIFont systemFontOfSize:13]];
    
    [self addSubview:tempLabel];
    
    return tempLabel;
}

#pragma mark - image创建的封装方法
- (UIImageView *)newImageAndImageName:(NSString *)imageName{
    
    UIImageView * tempImge = [[UIImageView alloc]init];
    
    tempImge.image = [UIImage imageNamed:imageName];
    
    [self addSubview:tempImge];
    
    return tempImge;
}

@end
